<script>

import * as echarts from 'echarts';
export default {
  name: 'VisualizationSix',
  data() {
    return{

    }
  },
  mounted() {
    this.getData();
  },
  methods: {
    getData() {
      this.$axios.get('/api/vis/data10', {

      }).then(res =>{
          if(res.data.code === 20041) {
            let data1 = [];
            for (let i = 0; i < res.data.data.length; i++) {
              data1.push(
              {
                value:res.data.data[i].param1,
                    name: res.data.data[i].param,
              },
              );
            }
            this.init(data1);
          }
      }).catch(error =>{
        this.open4(error);
      })
    },
    open4(msg) {
      this.$notify.error({
        title: msg,
        message: '这是一条错误的提示消息'
      });
    },
    init(data) {
      var chartDom = document.getElementById('main8');
      var myChart = echarts.init(chartDom);
      var option;

      const chartsData = data;
      option = {

        color: [
          "#ccffff",
          "#00ccff",
          "#00ff00",
          "#ffff00",
          "#ff9b00",
          "#ff0000",
          "#757f8d",
        ],
        tooltip: {
          trigger: "item",
          formatter: '{b} : {c} <br/>百分比 : {d}%' //{a}（系列名称），{b}（数据项名称），{c}（数值）, {d}（百分比）
        },
        title: {
          text: "5A级景区评分占比",
        },
        grid: {
          top: "30%",
          left: "0",
          right: "7",
          bottom: "15%",
          containLabel: true,
        },
        legend: {
          top: "center",
          right: 10,
          orient: "vertical",
          icon: "path://M7.424 476.672L301.312 778.24s205.312-204.288 425.984 0c3.072 1.024 291.84-301.568 291.84-301.568s-466.944-519.168-1011.712 0",
          textStyle: {
            color: "#000",
            fontSize: 14,
            fontWeight: 700,
            fontFamily: "Barlow Condensed SemiBold",
            rich: {
              name: {
                width: 60,
              },
              value: {
                width: 50,
              },
            },
          },
          formatter: (name) => {
            let res = chartsData.filter((v) => v.name === name);
            res = res[0] || {};
            const p = res.value;
            return (
                "{name|" +
                name +
                "}" +
                "{value|" +
                p +
                "}" 
            );
          },
        },
        series: [
          {
            type: "pie",
            radius: ["35%", "65%"],
            center: ["25%", "50%"],
            silent: true,
            itemStyle: {
              color: "#E5ECF6",
            },
            label: {
              show: false,
            },
            emphasis: {
              label: {
                show: false,
              },
            },
            labelLine: {
              show: false,
            },
            data: [0],
          },
          {
            type: "pie",
            radius: ["40%", "60%"],
            center: ["25%", "50%"],
            avoidLabelOverlap: false,
            z: 20,
            label: {
              show: false,
              position: "center",
            },
            emphasis: {
              label: {
                show: false,
                fontWeight: "bold",
              },
            },
            labelLine: {
              show: false,
            },
            data: chartsData,
          },
        ],
      };

      option && myChart.setOption(option);

    }
  }

}
</script>

<template>
  <div id="main8"></div>
</template>

<style scoped>
#main8 {
  width: 100%;
  height: 100%;
}
</style>